<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Promise学习</title>
	</head>
	<body>
		<!-- 
		Promise是一个类
		 1.Promise的基本使用
		 2.什么情况下会用到Promise  一般情况下有异步操作时  使用Promise对这个异步操作进行封装
		 
		 3.Promise的三种状态
			pending  等待状态
			fulfill  满足状态  当我们主动调用resolve时 就处于该状态 并且会回调.then()
			reject 拒绝状态  当我们主动回调了reject时  就处于该状态  并且会回调.catch()
		 
		 
		 
		 -->
		 <script type="text/javascript">
		 	setTimeout(() => {
				console.log('HelloWord');
			},1000)
			//参数 -> 函数
			//resolve  reject本身又是一个函数
			//链式编程
			/* new Promise((resolve,reject) => {
				setTimeout(() =>{
					resolve()
				},1000)
			}).then(() =>{
				console.log('xie')
				return new Promise((resolve,reject) => {
					setTimeout(() =>{
						resolve()
					},1000)
				})
			}).then(() =>{
				console.log('ying')
				return new Promise((resolve,reject) => {
					setTimeout(() =>{
						resolve()
					},1000)
				})
			}).then(() =>{
				console.log('peng')
				return new Promise((resolve,reject) => {
					setTimeout(() =>{
						resolve()
					},1000)
				}) */
			new Promise((resolve,reject) => {
				setTimeout(() => {
					//成功的时候
					resolve('HelloWorld')
					//失败的时候
					reject('error message')
				},1000)
			}).then((data) => {
				console.log(data);
				console.log(data);
				console.log(data);
			}).catch((err) => {
				console.log(err)
			})
		 </script>
	</body>
</html>
